<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;

/**
 * 身份认证
 *
 * @author Latrell Chan
 */
class AuthController extends Controller
{

	/**
	 * 登录页面
	 */
	public function getLogin()
	{
		return view('admin.auth.login2');
	}

	/**
	 * 登录操作
	 */
	public function postLogin(Request $request)
	{
		// 输入验证。
		$this->validate($request, [
			'username' => 'required|exists:admins',
			'password' => 'required|between:4,16'
		]);

		if (! Auth::admin()->attempt([
			'username' => $request->input('username'),
			'password' => $request->input('password')
		], $request->input('remember', 'false') == 'true')) {
			return $this->buildFailedValidationResponse($request, [
				[
					'用户名或密码不正确。'
				]
			]);
		}

		// 登录成功。
		return redirect()->intended(route('Dashboard'));
	}

	/**
	 * 退出登录
	 */
	public function anyLogout()
	{
		Auth::admin()->logout();
		return redirect()->route('Dashboard');
	}
}
